<?php
/**
 * Created by b17
 * 2/16/12 7:19 PM
 */

namespace Managers\Searchers;

abstract class Base
{
    /**
     * @var \Managers\Utils\SphinxManager
     */
    protected $sm;

    public function __construct($options = null)
    {
        $this->sm = new \Managers\Utils\SphinxManager();
        $this->sm->setAnyMatchMode();
        $this->init($options);
    }

    protected function init($options)
    {

    }

    final public function getResult()
    {
        $res = $this->sm->getResult();
        $this->throwIfError($res);
        return $res;
    }

    private function throwIfError($results)
    {
        foreach ($results as $result) {
            if (!empty($result['error'])) {
                throw new \Exception($result['error']);
            }
        }
    }

    public function setLimit($offset, $limit)
    {
        $this->sm->limit($offset, $limit);
    }
}
